package cn.haona.game.simb.wap.actions.login;

import java.util.Random;

import cn.haona.game.simb.comm.CommException;
import cn.haona.game.simb.object.department.HAB;
import cn.haona.game.simb.object.god.MainManager;
import cn.haona.game.simb.wap.actions.ActionSimbParent;

/**
 * 注册
 * @author Administrator
 *
 */
public class RegisterAction extends ActionSimbParent {

	private String loginname;
	private String password;
	private char sex;
	private String nickname;
	private String notice;
	
	/**
	 * 注册
	 * @return
	 */
	public String userRegister()
	{

		// 昵称为空
		boolean isEmptyNickName = false;

		// 登录名为空
		if (null == getLoginname() || "".equals(getLoginname()))
		{
			setNotice("登录名为空");
			return ERROR;
		}
		// 密码为空
		if (null == getPassword() || "".equals(getPassword()))
		{
			setNotice("密码为空");
			return ERROR;
		}
		// 昵称验证
		if (null == getNickname() || "".equals(getNickname()))
		{
			Random random=new Random();
			setNickname("火星人"+Math.abs(random.nextInt()));
		}
		
		//注册用户
		HAB hab=MainManager.getInstance().getEntityManager().getHab();
		try
		{
			hab.registerUser(loginname, password, nickname, sex);
		}
		catch(CommException e)
		{
			e.printStackTrace();
			notice=e.getMessage();
			return ERROR;
		}
		
		return SUCCESS;
	}

	public String getLoginname() {
		return loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}



	public char getSex() {
		return sex;
	}

	public void setSex(char sex) {
		this.sex = sex;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getNotice() {
		return notice;
	}

	public void setNotice(String notice) {
		this.notice = notice;
	}
	
}
